import 'package:flutter/material.dart';

class AfPopContentView extends StatelessWidget {
  const AfPopContentView(
      {Key? key,
      required this.content,
      this.borderRadius,
      this.titlePadding,
      this.contentPadding,
      this.insetPadding,
      this.backgroundColor,
      this.willPop})
      : super(key: key);

  final Widget content;
  final double? titlePadding;
  final double? borderRadius;
  final double? contentPadding;
  final EdgeInsets? insetPadding;
  final Color? backgroundColor;
  final bool? willPop;
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: AlertDialog(
          title: SizedBox(
            height: titlePadding ?? 20,
          ),
          titleTextStyle: const TextStyle(fontSize: 20, color: Colors.black),
          titlePadding: const EdgeInsets.only(top: 0),
          insetPadding: insetPadding ??
              const EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0),
          contentPadding:
              EdgeInsets.symmetric(horizontal: contentPadding ?? 26),
          backgroundColor:
              backgroundColor ?? const Color(0xffFFFFFF).withOpacity(1),
          content: content,
          elevation: 0,
          shape: RoundedRectangleBorder(
              borderRadius:
                  BorderRadius.all(Radius.circular(borderRadius ?? 18))),
        ),
        onWillPop: () async => willPop ?? true);
  }
}

Future<void> showContentPopView(
  BuildContext context, {
  required Widget content,
  double? titlePadding,
  double? borderRadius,
  double? contentPadding,
  EdgeInsets? insetPadding,
  Color? backgroundColor,
  bool barrierDismissible = true,
  bool willPop = true,
}) async {
  showDialog(
    context: context,
    barrierDismissible: barrierDismissible,
    builder: (ctx) => AfPopContentView(
      content: content,
      borderRadius: borderRadius,
      titlePadding: titlePadding,
      backgroundColor: backgroundColor,
      contentPadding: contentPadding,
      insetPadding: insetPadding,
      willPop: willPop,
    ),
  );
}
